<?php
require_once("engine/www/combustion.php");

$type 	= isset($_GET['tpe'])?$_GET['tpe']:"h1";
$string = isset($_GET['str'])?$_GET['str']:" ";

$style	= json_decode( engine_get( 'style:'.$type ));

$font	= ROOT . ACCOUNT ."/www". THEME ."fonts/".$style->font;
$fsize	= $style->fsize;
$fcolor	= $style->fcolor;
$angle	= ( $style->angle )? $style->angle : 0;

$file	= ROOT . ACCOUNT ."/www". THEME ."img/txtdump/$type.$fsize.".urlencode($string).".png";

// WORK IT, BABY!
header("Content-type: image/png");

if( file_exists($file) ) readfile($file);
else{
	
	$string = urldecode($string);

	//TRACE TEXTBOX
	$dummy 		= imagettfbbox($fsize, $angle, $font, 'OAÉ039ghj');
	$textbox	= imagettfbbox($fsize, $angle, $font, $string);
	$box 		= array('w'=>abs($textbox[0])+$textbox[2]+2, 'h'=>abs($dummy[7])+$dummy[1], 'x'=>$textbox[0]+1, 'y'=>abs($dummy[7]) );
	
	if( $angle )
		if($type=="menu" || $type=="menu.a" || $type=="menu.sub") { $box['w'] += 6; $box['x'] += 4; $box['h'] += 8; $box['y'] += 8; }
	else
		if($type=="menu" || $type=="menu.a") { $box['w'] += 16; $box['x'] += 8; }
		
	$image = imagecreatetruecolor($box['w'], $box['h']);
	imagesavealpha($image, true);
	imagealphablending($image, false);
	
	$tlo = imagecolorallocatealpha($image, 0, 0, 0, 127);
	$tlt = imagecolorallocate($image, $fcolor[0], $fcolor[1], $fcolor[2]);
	imagefill($image, 0, 0, $tlo);
	
	imagesavealpha($image, true);
	imagealphablending($image, true);
	imagettftext ($image, $fsize, $angle, $box['x'], $box['y'], $tlt, $font, $string);
	
	imagepng($image,$file);
	imagepng($image);
	imagedestroy($image);

}

?> 